#include "scene.h"
#include "ui_scene.h"

Scene::Scene(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Scene)
{
    ui->setupUi(this);

    void(Scene::*regptr)() = &Scene::registerr;

    connect(ui->button3, &QPushButton::clicked, this, regptr);

}

Scene::~Scene()
{
    delete ui;
}

void Scene::registerr()
{
    // 用户输入的用户名
    QString username = ui->register_user->text();

    if (config.userNameExist(username)) {
        // 用户名合法，注册新用户
        User user(ui->register_user->text(), ui->register_pwd->text());
        config.userList.push_back(user);

        // 界面跳转
        MainWindow * login = new MainWindow;
        this->hide();
        login->show();

        qDebug() << "【注册成功】用户名合法";
    }
    else
        qDebug() << "【注册失败】用户名重复";
}
